package com.holyant.goods.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.core.annotation.Excel;
import com.ruoyi.common.core.domain.BaseDto;
import com.ruoyi.common.utils.LocalDateTimeUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
import com.holyant.goods.enums.GdsSkuPurchasePriceCurTypeEnum;
import com.holyant.goods.enums.QuotMethodEnum;
import com.holyant.goods.enums.QuoteSalesChannel;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * 商品调价申请dto
 * 
 * @author fkmalls
 * @date 2022-02-10
 */
@Data
@ApiModel("商品调价申请")
public class GdsSkuQuoteDto extends BaseDto{

    private static final long serialVersionUID = 1L;

    /** 编码 */
    @Excel(name = "编码")
    @ApiModelProperty(value = "编码")
    private String code;
    /** 报价类型(10成本价20结算价) */
    @Excel(name = "报价类型(10成本价20结算价)")
    @ApiModelProperty(value = "报价类型(10成本价20结算价)")
    private Integer quoteType;
    /** 店铺id */
    @ApiModelProperty(name = "店铺id")
    private Long shopId;
    /** 店铺名称 */
    @ApiModelProperty(name = "店铺名称")
    private String shopName;
    /** 客户id */
    @ApiModelProperty(name = "客户id")
    private Long customerId;
    /** 客户名称 */
    @ApiModelProperty(name = "客户名称")
    private String customerName;
    /**
     * 平台
     */
    private String platform;
    /** 企业id */
    @Excel(name = "企业id")
    @ApiModelProperty(value = "企业id")
    private Long enterpriseId;
    /** 企业名称 */
    @Excel(name = "企业名称")
    @ApiModelProperty(value = "企业名称")
    private String enterpriseName;
    /** 渠道 */
    @Excel(name = "渠道")
    @ApiModelProperty(value = "渠道")
    @NotNull(message = "渠道类型不能为空")
    private Integer salesChannel;

    @ApiModelProperty(value = "渠道名称")
    private String salesChannelName;

    /** 客户结算报价方式 */
    @Excel(name = "客户结算报价方式")
    @ApiModelProperty(value = "客户结算报价方式")
    private Integer settleQuotMethod;
    /** 申请时间 */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Excel(name = "申请时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "申请时间")
    private LocalDateTime applyTime;

    /** 申请人id */
    @ApiModelProperty(value = "申请人id")
    private String applyUserId;
    /** 申请人名称 */
    @ApiModelProperty(value = "申请人名称")
    private String applyUserName;
    /** 流程实例id */
    @ApiModelProperty(value = "流程实例id")
    private String instanceId;
    /** 流程定义key */
    @ApiModelProperty(value = "流程定义key")
    private String processKey;

    /** 有效时间开始 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "有效时间开始", width = 30, dateFormat = "yyyy-MM-dd")
    @ApiModelProperty(value = "有效时间开始")
    @NotNull(message = "生效日期不能为空")
    private LocalDate effectiveTimeStart;

    /** 有效时间结束 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "有效时间结束", width = 30, dateFormat = "yyyy-MM-dd")
    @ApiModelProperty(value = "有效时间结束")
    private LocalDate effectiveTimeEnd;
    /** 审核状态  10 待审核 50 审核中  100 已审核 */
    @Excel(name = "审核状态  10 待审核 50 审核中  100 已审核")
    @ApiModelProperty(value = "审核状态  10 待审核 50 审核中  100 已审核")
    private Integer auditStatus;
    /** 审核人id */
    @Excel(name = "审核人id")
    @ApiModelProperty(value = "审核人id")
    private Long auditById;
    /** 审核人名称 */
    @Excel(name = "审核人名称")
    @ApiModelProperty(value = "审核人名称")
    private String auditByName;
    /** 审核时间 */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Excel(name = "审核时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "审核时间")
    private LocalDateTime auditTime;
    @Excel(name = "初审人id")
    @ApiModelProperty(value = "审核人id")
    private Long preAuditById;
    /** 审核人名称 */
    @Excel(name = "初审人名称")
    @ApiModelProperty(value = "初审人名称")
    private String preAuditByName;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Excel(name = "审核时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "初审时间")
    private LocalDateTime preAuditTime;
    @ApiModelProperty(value = "'驳回人id'")
    private Long rejectById;
    /** 审核人名称 */
    @ApiModelProperty(value = "'驳回人姓名")
    private String rejectByName;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "'驳回时间'")
    private LocalDateTime rejectTime;
    /** 更新标记 0：未更新、1：已更新 */
    @Excel(name = "更新标记 0：未更新、1：已更新")
    @ApiModelProperty(value = "更新标记 0：未更新、1：已更新")
    private String updateFlag;
    /** 停用标签 */
    @Excel(name = "停用标签")
    @ApiModelProperty(value = "停用标签")
    private String closeFlag;
    /** 描述 */
    @Excel(name = "描述")
    @ApiModelProperty(value = "描述")
    @NotEmpty(message = "调价申请原因不能为空")
    private String remark;
    /** 版本号 */
    @Excel(name = "版本号")
    @ApiModelProperty(value = "版本号")
    private Long ver;

    @ApiModelProperty(value = "报价方式")
    private Integer quoteMethod;

    @ApiModelProperty(value = "删除标识")
    private String delFlag;

    @Valid
    @NotEmpty(message = "请添加需要调价的sku")
    private List<GdsSkuQuoteItemDto> itemDtoList;

    @ApiModelProperty(value = "导出的字段")
    private List<GdsSkuQuotePublicImportDto> itemExportList;
    @ApiModelProperty(value = "币种")
    private Integer curType;
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        GdsSkuQuoteDto that = (GdsSkuQuoteDto) o;
        return Objects.equals(quoteType, that.quoteType) &&
                Objects.equals(enterpriseId, that.enterpriseId) &&
                Objects.equals(salesChannel, that.salesChannel) &&
                Objects.equals(effectiveTimeStart, that.effectiveTimeStart) &&
                Objects.equals(effectiveTimeEnd, that.effectiveTimeEnd);
    }

    @Override
    public int hashCode() {
        return Objects.hash(quoteType, enterpriseId, salesChannel, effectiveTimeStart, effectiveTimeEnd);
    }


    public List<GdsSkuQuotePublicImportDto> convertSkuQuotePublicImportDto(){
        List<GdsSkuQuotePublicImportDto> gdsSkuQuotePublicImportDtos = new ArrayList<>(this.itemDtoList.size());
        GdsSkuQuotePublicImportDto gdsSkuQuotePublicImportDto = null;
        for (GdsSkuQuoteItemDto gdsSkuQuoteItemDto : this.itemDtoList) {
            gdsSkuQuotePublicImportDto = new GdsSkuQuotePublicImportDto();
            BeanUtils.copyBeanProp(gdsSkuQuoteItemDto,gdsSkuQuotePublicImportDto);
            // salesChannel
            gdsSkuQuotePublicImportDto.setSalesChannel(null == salesChannel? null : QuoteSalesChannel.getNameByCode(salesChannel));
            // quoteMethod
            gdsSkuQuotePublicImportDto.setQuoteMethod(null == gdsSkuQuoteItemDto.getQuoteMethod() ? null : QuotMethodEnum.getNameByCode(gdsSkuQuoteItemDto.getQuoteMethod()));
            // curType
            gdsSkuQuotePublicImportDto.setCurType(null == gdsSkuQuoteItemDto.getCurType() ? null : GdsSkuPurchasePriceCurTypeEnum.getNameByCode(gdsSkuQuoteItemDto.getCurType()));
            // 效期
            gdsSkuQuotePublicImportDto.setExpireDate(LocalDateTimeUtils.format(gdsSkuQuoteItemDto.getExpireDate()));
            // 初始化价格信息
            gdsSkuQuotePublicImportDto.initPrice();
            gdsSkuQuotePublicImportDtos.add(gdsSkuQuotePublicImportDto);
        }
        return gdsSkuQuotePublicImportDtos;
    }


    public String getSalesChannelName() {
        if (null != this.salesChannel){
            return QuoteSalesChannel.getNameByCode(this.salesChannel);
        }
        return salesChannelName;
    }
}
